** Replication Code for:
** Terrorism Activates Ethnocentrism to Explain Greater Willingness to 
** Sacrifice Civil Liberties: Evidence from Germany
** Authors: Christina Novak Hansen and Peter Thisted Dinesen 
** Date: 10/02/2021

*-------------------------------------------------------------------------------

clear all
use GGSS2016_analysis.dta
svyset xs11 [pweight=wghtpew], vce(linearized)
keep if german==1 & governmentsplit!=.					

*-------------------------------------------------------------------------------
*Appendix Q: Additional robustness checks: the interaction affect for wider 
*post-attacks groups  
*-------------------------------------------------------------------------------


*-------------------------------------------------------------------------------
	***The interaction effect when widening the post-attacks group by 1 day***
*-------------------------------------------------------------------------------


/*In the following, the main model is recalculated for new definitions of the 
post-attacks group, which is widened by one day until the post-attacks group 
consist of the respondents interviewed in the first 30 days after the attacks.
The pre-attacks group remains the same, meaning the respondents interviewed in 
the 20 days prior to the wave of terrorist attacks in July 2016.
*/

********************************************************************************

*1: Generating window dummy variables
gen treatmentwidth7 = 1 if respid!=. & (edate>=td(27/07/2016) & edate<=td(02/08/2016))
gen treatmentwidth8 = 1 if respid!=. & (edate>=td(27/07/2016) & edate<=td(03/08/2016))
gen treatmentwidth9 = 1 if respid!=. & (edate>=td(27/07/2016) & edate<=td(04/08/2016))
gen treatmentwidth10 = 1 if respid!=. & (edate>=td(27/07/2016) & edate<=td(05/08/2016))
gen treatmentwidth11 = 1 if respid!=. & (edate>=td(27/07/2016) & edate<=td(06/08/2016))
gen treatmentwidth12 = 1 if respid!=. & (edate>=td(27/07/2016) & edate<=td(07/08/2016))
gen treatmentwidth13 = 1 if respid!=. & (edate>=td(27/07/2016) & edate<=td(08/08/2016))
gen treatmentwidth14 = 1 if respid!=. & (edate>=td(27/07/2016) & edate<=td(09/08/2016))
gen treatmentwidth15 = 1 if respid!=. & (edate>=td(27/07/2016) & edate<=td(10/08/2016))
gen treatmentwidth16 = 1 if respid!=. & (edate>=td(27/07/2016) & edate<=td(11/08/2016))
gen treatmentwidth17 = 1 if respid!=. & (edate>=td(27/07/2016) & edate<=td(12/08/2016))
gen treatmentwidth18 = 1 if respid!=. & (edate>=td(27/07/2016) & edate<=td(13/08/2016))
gen treatmentwidth19 = 1 if respid!=. & (edate>=td(27/07/2016) & edate<=td(14/08/2016))
gen treatmentwidth20 = 1 if respid!=. & (edate>=td(27/07/2016) & edate<=td(15/08/2016))
gen treatmentwidth21 = 1 if respid!=. & (edate>=td(27/07/2016) & edate<=td(16/08/2016))
gen treatmentwidth22 = 1 if respid!=. & (edate>=td(27/07/2016) & edate<=td(17/08/2016))
gen treatmentwidth23 = 1 if respid!=. & (edate>=td(27/07/2016) & edate<=td(18/08/2016))
gen treatmentwidth24 = 1 if respid!=. & (edate>=td(27/07/2016) & edate<=td(19/08/2016))
gen treatmentwidth25 = 1 if respid!=. & (edate>=td(27/07/2016) & edate<=td(20/08/2016))
gen treatmentwidth26 = 1 if respid!=. & (edate>=td(27/07/2016) & edate<=td(21/08/2016))
gen treatmentwidth27 = 1 if respid!=. & (edate>=td(27/07/2016) & edate<=td(22/08/2016))
gen treatmentwidth28 = 1 if respid!=. & (edate>=td(27/07/2016) & edate<=td(23/08/2016))
gen treatmentwidth29 = 1 if respid!=. & (edate>=td(27/07/2016) & edate<=td(24/08/2016))
gen treatmentwidth30 = 1 if respid!=. & (edate>=td(27/07/2016) & edate<=td(25/08/2016))




foreach var of varlist treatmentwidth* {
	gen c`var' = `var'
}

*Dummy variables
*Control=0 
foreach var of varlist ctreatmentwidth* {
	replace `var' = 0 if treatment1==0	
}

save GGSS2016_treatmentwide.dta, replace
********************************************************************************


*2: Estimating interaction effect for each window and variable per matched sample

*Interaction effects on civil liberties with reference to terrorism
*Ethnocentrism
tempname e_twidth_C
postfile `e_twidth_C'  e_twidth_c_coef e_twidth_c_SE e_twidth_c_pval using e_twidth_C.dta, replace
foreach var of varlist ctreatmentwidth*{
	qui svy: regress st_terrori c.`var'##c.st_ethno i.sex st_age st_age2 i.proedu2 i.work2
	matrix define temp5=r(table)
	post `e_twidth_C'  (`=_b[`var'#st_ethno]') (`=_se[`var'#st_ethno]') (`=temp5[4,3]')
}
postclose `e_twidth_C'
********************************************************************************


*3: Generating variables for 95% CI's, upper and lower limits
clear
use e_twidth_C.dta 
gen startday =_n
gen treatdays = startday + 6
save e_twidth_C.dta, replace
gen e_cwidth_LB = e_twidth_c_coef - 1.96*e_twidth_c_SE
gen e_cwidth_UB = e_twidth_c_coef + 1.96*e_twidth_c_SE



order startday ///
	e_twidth_c_coef e_twidth_c_SE e_cwidth_LB e_cwidth_UB e_twidth_c_pval 
save treatmentwidth_figure.dta, replace
********************************************************************************


*4: Plotting the estimated coefficients and calculated 95%-CIs

							***Figure Q1***

clear 
use treatmentwidth_figure.dta

twoway (connected e_twidth_c_coef treatdays, mcolor(gs3) msymbol(circle_hollow) ///
lcolor(gs3)) (scatter e_twidth_c_coef treatdays if e_twidth_c_pval<=0.05, ///
mcolor(black) msymbol(circle)), ytitle(Activation Effect (Interaction Term)) ///
ytitle(, size(medium)) ylabel(, labsize(medium) angle(horizontal) grid) ///
ymtick(0.3(0.05)0.7, grid) xtitle(Expanding width of post-attacks group by 1 day) ///
xtitle(, size(medium) margin(medium)) xlabel(7(1)30, labsize(medium) grid) ///
legend(order(1 "Ethnocentrism (insignificant)" 2 "Ethnocentrism (significant)") ///
rows(1) size(medium) region(lcolor(none))) xsize(7)	
graph export Figure_Q1.pdf, replace

********************************************************************************


*5: Checking the regressions
clear 
use GGSS2016_treatmentwide.dta


foreach var of varlist ctreatmentwidth*{
	svy: regress st_terrori c.`var'##c.st_ethno i.sex st_age st_age2 i.proedu2 i.work2
}

tab ctreatmentwidth7 if st_terrori!=. & st_ethno!=. & sex!=. & st_age!=. & proedu2!=. & work2!=. 
tab ctreatmentwidth16 if st_terrori!=. & st_ethno!=. & sex!=. & st_age!=. & proedu2!=. & work2!=. 
tab ctreatmentwidth30 if st_terrori!=. & st_ethno!=. & sex!=. & st_age!=. & proedu2!=. & work2!=. 
di 142/52
*=2.73
*-------------------------------------------------------------------------------


